local que_gangkai = fk.CreateSkill {
    name = "que_gangkai",
    anim_type = "control",
}
Fk:loadTranslationTable {
    ["que_gangkai"] = "杠开",
    [":que_gangkai"] = "每回合限一次，当你使用【杀】指定目标时，若你的“杠”数量等于此杀的点数，你可以对此【杀】的目标依次使用所有“杠”，" ..
        "将体力上限调整至4点；若目标因此死亡，你摸X张牌，否则，你弃置所有手牌；若存活人数不大于4人，“杠”双倍点数的【杀】也可使用该技能。(X为因此调整的体力上限)。",

    ["#que_gangkai-invoke"] = "杠开：是否对 %dest 使用所有“杠”？",
    ["#que_gangkai-use"] = "杠开：请选择一张对 %dest 使用的牌？",
    ["#que_gangkai-second"] = "杠开：选择 %arg 的另一个目标",
}
que_gangkai:addEffect(fk.TargetSpecifying, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(que_gangkai.name) and data.card.trueName == "slash" and target == player
            and player:usedSkillTimes(que_gangkai.name, Player.HistoryPhase) == 0 then
            if #player.room.alive_players > 4 then
                return #player:getPile("zny_gang") == data.card.number
            else
                return #player:getPile("zny_gang") == data.card.number or
                    #player:getPile("zny_gang") * 2 == data.card.number
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
            skill_name = que_gangkai.name,
            prompt = "#que_gangkai-invoke::" .. data.to.id,
        })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        while #player:getPile("zny_gang") > 0 and not player.dead and not data.to.dead do
            if data.to.dead then break end
            local id = room:askToCards(player, {
                min_num = 1,
                max_num = 1,
                pattern = ".|.|.|zny_gang",
                prompt = "#que_gangkai-use::" .. data.to.id,
                skill_name = "zny_gang",
                cancelable = false,
                expand_pile = "zny_gang",
            })[1]
            local card = Fk:getCardById(id)
            if player:canUseTo(card, data.to, { bypass_distances = true, bypass_times = true }) then
                local use = {
                    from = player,
                    tos = { data.to },
                    card = card,
                    extra_data = {
                        que_gangkai_use = player,
                    }
                }
                room:useCard(use)
            else
                room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, que_gangkai.name, nil, true,
                    player)
            end
        end
        local x
        if player.maxHp == 4 then return end
        if player.maxHp > 4 then
            x = player.maxHp - 4
            room:changeMaxHp(player, -x)
        else
            x = 4 - player.maxHp
            room:changeMaxHp(player, x)
        end
        room:setPlayerMark(player, "gangkai_point-turn", x)
        if player.dead then return end
        if data.to.dead then
            player:drawCards(x, que_gangkai.name)
        else
            player:throwAllCards("h", que_gangkai.name)
        end
    end,
})
return que_gangkai
